var goodsStar = 0;
var packageStar = 0;
var carryStar = 0;
var serveStar = 0
	/*控制打分*/
function ChangeImg(obj, oevent, oldsrc, newsrc) {
	var uls = document.getElementById("uls");
	//取的多余打分内容对象
	var ArrayImgs = obj.getElementsByTagName("img");
	//获得obj下的的图片对象数组
	var e = oevent || window.event;
	//事件对象
	var Target = e.target || e.srcElement;
	//确定事件对象
	for (var i = 0; i < ArrayImgs.length; i++) {
		ArrayImgs[i]._num = i;
		//为每一个图片对象添加一个属性
	}
	if (Target.tagName == "IMG") { //判断单击的事件对象是不是图片
		var uls=document.getElementById("uls");
		uls.style.height="106px";
		uls.style.opacity=1;
		for (var j = 0; j < ArrayImgs.length; j++) {
			if (j <= Target._num) {
				ArrayImgs[j].src = "../../image/" + newsrc;
			} else {
				ArrayImgs[j].src = "../../image/" + oldsrc;
			}
		}
	}
	stars = Target._num + 1;
	return stars;
}

//控制文本框内容
function check(obj) {
	if (obj.value === "亲，商品满意吗？您对我们的服务有哪些建议？") {
		obj.value = "";
		obj.style.color = "#000";
	}
}

function checkout(obj) {
	if (obj.value.length == 0) {
		obj.value = "亲，商品满意吗？您对我们的服务有哪些建议？"
		obj.style.color = "#AFAFAF";
	}
}

//控制上传图片的显示
function openImg(obj) {
	api.confirm({
		title: "提示",
		msg: "从哪里取的图片",
		buttons: ["拍照", "相册", "取消"]
	}, function(ret, err) {
		var sourcetype;
		if (ret.buttonIndex == 3) {
			return;
		}
		if (ret.buttonIndex == 1) {
			sourcetype = 'camera';
		}
		if (ret.buttonIndex == 2) {
			sourcetype = 'album';
		}
		api.getPicture({
			sourceType: sourcetype,
			encodingType: 'jpg',
			mediaValue: 'pic',
			destinationType: 'url',
			allowEdit: true,
			quality: 100,
			saveToPhotoAlbum: false
		}, function(ret, err) {
			if (ret) {
				Receive(obj, ret.data);
			} else {
				api.alert({
					title: '提示',
					msg: err.msg,
					buttons: ['确定']
				}, function(ret, err) {
					//coding...
				});
			}
		});
	});
}

//函数控制上传关闭图片的隐藏于显示 obj代表被点击的对象 src取的图片的地址
function Receive(obj, str) {
	obj.src = str;
	var guanbibtn = $(obj).parent().find(".guanbi");
	guanbibtn.show().click(function() {
		obj.src = "../../image/pl_tp.png";
		guanbibtn.hide()
	});
}

function goodsstar(obj, str) {
	//获得obj下的的图片对象数组
	var e = str || window.event;
	//事件对象
	var Target = e.target || e.srcElement;
	if (Target.tagName != "IMG") {
		return
	};
	goodsStar = ChangeImg(obj, str, 'pl_dxxs.png', 'pl_dxx.png');
}

function packagestar(obj, str) {
	//获得obj下的的图片对象数组
	var e = str || window.event;
	//事件对象
	var Target = e.target || e.srcElement;
	if (Target.tagName != "IMG") {
		return
	};
	packageStar = ChangeImg(obj, str, 'pl_xxs.png', 'pl_xx.png');
}

function carrystar(obj, str) {
	//获得obj下的的图片对象数组
	var e = str || window.event;
	//事件对象
	var Target = e.target || e.srcElement;
	if (Target.tagName != "IMG") {
		return
	};
	carryStar = ChangeImg(obj, str, 'pl_xxs.png', 'pl_xx.png');
}

function servestar(obj, str) {
	//获得obj下的的图片对象数组
	var e = str || window.event;
	//事件对象
	var Target = e.target || e.srcElement;
	if (Target.tagName != "IMG") {
		return
	};
	serveStar = ChangeImg(obj, str, 'pl_xxs.png', 'pl_xx.png');
}

function orderPj($scope, $http) {
	var orders = eval('(' + readData(localStorage.order) + ')');
	$scope.order = orders;
	var goods = orders.list;
	goodsId = orders.orderdetailid;
	for (var i = 0; i < goods.length; i++) {
		var id = goods[i]['orderdetailid'];
		if (id == goodsId) {
			$scope.goods = goods[i];
		}
	}
	$scope.submit = function() {
		//alert('图片上传未处理')
		var content = document.getElementById('text_area').value.replace(/\s/g, '');
		if (goodsStar == 0 || packageStar == 0 || carryStar == 0 || serveStar == 0) {
			mui.toast('请对商品，以及包装、服务、物流进行打分')
			return;
		} else {
			if (content == "亲，商品满意吗？您对我们的服务有哪些建议？" || content.length <= 0) {
				mui.toast('请输入商品评价内容')
				return;
			} else {
				//alert('接口待调整，订单商品中没有明细ID')
				url = getUrl("31orderPj");
				header = getHeader();
				datas = 'productID=' + $scope.goods["productid"] + '&account=' + readData(localStorage.phone) + '&orderID=' + orders.orderId + '&orderdetailID=' + $scope.goods['orderdetailid'] + '&content=' + document.getElementById('text_area').value + '&star=' + goodsStar + '&packageStar=' + packageStar + '&expressStar=' + carryStar + '&serviceStar=' + serveStar + '&nickname' + readData(localStorage.nickName);
				plus.nativeUI.showWaiting("正在提交…")
				$http({
					method: 'POST',
					url: url,
					headers: header,
					timeout: 10000,
					//cache: true,
					data: datas
				}).success(function(data, status, headers, config) {
					plus.nativeUI.closeWaiting()
					if (data.msg == 'success') {
						//查找当前商品，修改商品的评价状态,并保存localstorage.order
						delete orders.goodsId
						for (var i = 0; i < orders.list.length; i++) {
							if (orders.list[i]['orderdetailid'] == goodsId) {
								orders.list[i]['iscomment'] = 'y'
							}
						}
						localStorage.order = writeData(JSON.stringify(orders));
						//刷新评价状态
						var parent=plus.webview.currentWebview().opener();
						mui.fire(parent,"reloadthis")
						refreshOrderManager();
							//返回评价列表窗口
						setTimeout(function() {
							mui.back()
						}, 500)
					} 
					
				}).error(function(data, status, headers, config) {
					mui.toast("网络连接异常，请稍后重试(e)")
					plus.nativeUI.closeWaiting()
				});
			}
		}
	}
}